import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

/**
 * 插件
 * */
import './plugins/axios'
import './plugins/element'
import './plugins/echarts'
import api from './api'


// api接口
Vue.prototype.api = api


Vue.prototype.handleRes = function (res) {
  if (!res.data.code) {
    alert('省平台数据不规范，原返回值为' + res.data.non_json_response)
    this.cusMark(res)
  } else {
    alert(res.data.message.replace(/#/g, '\r\n'))
    this.cusMark(res)
  }
}
Vue.prototype.serverError = function () {
  alert('服务器无法连接');
}
Vue.prototype.enterClick = function (fn_name) {
  let _this = this;
  console.log(1);
  document.onkeypress = function (e) {
    if (e.key == 'Enter' && fn_name && _this.$route.meta.enterClick) {
      _this[fn_name]();
      console.log(1);
    }
  }
}

console.log(api);

// 组件
import './components'

// 公用样式
require('./assets/style/Common.scss')
require('./assets/style/Components.scss')

Vue.prototype.handleRes = function (res) {
  if (!res.data.code) {
    alert('省平台数据不规范，原返回值为' + res.data.non_json_response)
    this.cusMark(res)
  } else {
    alert(res.data.message.replace(/#/g, '\r\n'))
    this.cusMark(res)
  }
}

// 窗口自适应浏览器高度
// Vue.prototype.initModalHeight = function(modal) {
//   console.log(this.$store.state.clientHeight);
//   console.log(this.$refs[modal].$el.children[0]);
//   this.$refs[modal].$el.children[0].style.height = this.$store.state.clientHeight - 200 + 'px';
// }

Vue.prototype.goIndex = function (route) {
  console.log(1);
  this.$router.push(route)
}
Vue.prototype.cusMark = function (res) {
  const loading = this.$loading({
    lock: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  if (res) {
    loading.close();
  }
}

Vue.prototype.showForm = function (name) {
  this[name] = true
}
Vue.prototype.hideForm = function (name) {
  this[name] = false
}

Vue.config.productionTip = false  //开发环境下提供打印警告 错误 生产环境下不打印 节省资源消耗

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
